package mappedClass;

// Generated 3 juil. 2014 12:40:01 by Hibernate Tools 3.4.0.CR1

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Team generated by hbm2java
 */
@Entity
@Table(name = "team", catalog = "test")
public class Team implements java.io.Serializable {

	private int id;
	private User user;
	private String name;
	private Set<UserTeamHistory> userteamhistories = new HashSet<UserTeamHistory>(
			0);
	private Set<TeamConfiguration> teamconfigurations = new HashSet<TeamConfiguration>(
			0);
	private Set<Task> tasks = new HashSet<Task>(0);

	public Team() {
	}

	public Team(User user, String name) {
		this.user = user;
		this.name = name;
	}

	public Team(int id, User user, String name,
			Set<UserTeamHistory> userteamhistories,
			Set<TeamConfiguration> teamconfigurations, Set<Task> tasks) {
		this.id = id;
		this.user = user;
		this.name = name;
		this.userteamhistories = userteamhistories;
		this.teamconfigurations = teamconfigurations;
		this.tasks = tasks;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "teamLeaderId", nullable = false)
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "name", nullable = false, length = 65535)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@OneToMany(fetch = FetchType.LAZY)
	public Set<UserTeamHistory> getUserteamhistories() {
		return this.userteamhistories;
	}

	public void setUserteamhistories(Set<UserTeamHistory> userteamhistories) {
		this.userteamhistories = userteamhistories;
	}

	@OneToMany(fetch = FetchType.LAZY)
	public Set<TeamConfiguration> getTeamconfigurations() {
		return this.teamconfigurations;
	}

	public void setTeamconfigurations(Set<TeamConfiguration> teamconfigurations) {
		this.teamconfigurations = teamconfigurations;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "teamtask", catalog = "test", joinColumns = { @JoinColumn(name = "teamId", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "taskId", nullable = false, updatable = false) })
	public Set<Task> getTasks() {
		return this.tasks;
	}

	public void setTasks(Set<Task> tasks) {
		this.tasks = tasks;
	}

	public String displayTasks(Set<Task> tasks) {
		Iterator<Task> iterator = tasks.iterator();
		String sTask = "";
		while (iterator.hasNext()) {
			sTask += iterator.next().getDescription() + " -- ";
		}
		
		return sTask;
	}

	@Override
	public String toString() {
		return "Team [id=" + id + ", user=" + user + ", name=" + name
				+ ", userteamhistories=" + userteamhistories
				+ ", teamconfigurations=" + teamconfigurations + ", tasks="
				+ tasks;
	}

}
